{% extends './base.html' %}
{% block title %}
<title>{{page_title}}-忘记密码</title>
<script src="/public/assets/common/vue.v2.5.1.min.js"></script>
<script>
    Vue.options.delimiters = ['${', '}'];
</script>
<style>
    .error {
        color: red !important;
    }

    input.error {
        border: 1px dotted red !important;
    }
    .style-valid {
        background: gray;
        color: white;
    }
</style>
<script src="/public/assets/common/jquery/jquery.validate.min.js"></script>
<script src="/public/assets/common/jquery/messages_zh.min.js"></script>
<script src="/public/assets/common/jsencrypt.min.js"></script>
{% endblock %}
{% block nav %}
{% endblock %}
{% block body %}
<div id="main-container" class="account-page no-header-top">
    <div class="page-top-leader omega">
        <div class="container_12 relatived clearfix">
            <h1 class="page-title">修改密码</h1>
            <div class="breadcrumb">
                <span class="br_before">当前位置:</span>
                <a href="/">首页</a>
                <span class="br_sep">/</span>
                <span class="cur_link">修改密码</span>
            </div>
        </div>
    </div><!-- .page-top-leader -->
    <div class="container_12">
        <div class="aside-container grid_9">
            <div class="content">
                <h3>设置密码</h3>
                <form action="" method="" id="form_pass">
                    <label>原密码(*):</label>
                    <br>
                    <input class="full-width"  type="password" name="oldPassword" v-model="oldPassword" minlength="6" placeholder="" required>
                    <br>
                    <br>
                    <label>新密码(*):</label>
                    <br>
                    <input class="full-width" id="password1" type="password" name="password" minlength="6" placeholder="" required>
                    <br>
                    <br>
                    <label>确认密码(*):</label>
                    <br>
                    <input class="full-width" type="password" name="comfirmPassword" v-model="password" minlength="6" equalTo="#password1" placeholder="" required>
                    <br>
                    <br>
                    <input  class="style-button " type="submit" value="提交"/>
                </form>
            </div>
        </div>
        <div id="column-left" class="grid_3 aside omega">
            <div class="box">
                <div class="box-heading">账户管理</div>
                <div class="box-content">
                    <div class="box-category">
                        <ul>
                            <li><a class="active" href="/shop/uc">我的账户</a></li>
                            <li><a href="/shop/wishlist">收藏夹</a></li>
                            <li><a href="/shop/myProduct">我的仓库</a></li>
                            <li><a href="/shop/order">我的订单</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div><!--end #column-left -->      </div><!-- end .container_12 -->
</div><!-- end #main-container -->
<script>
    let app = new Vue({
        el: '#form_pass',
        data: {
            oldPassword: '',
            password: ''
        }
    });
</script>
<script>
    $(function () {
        $("#form_pass").validate({
            debug: true,
            submitHandler: function (form) {
                //Ap.loading.start();
                let encrypt = new JSEncrypt();
                encrypt.setPublicKey(public_key);
                let json = {oldPassword: app.oldPassword,newPassword:app.password};
                let data = JSON.stringify(json);
                let encrpted = encrypt.encrypt(data);
                if(!encrpted){
                    Ap.msg.error("encrpted is error");
                }else {
                    Ap.request.post('/shop/updatePassword', {content: encrpted}, function (res) {
                        //Ap.loading.end();
                        if (res.success) {
                            Ap.msg.alert("密码修改成功，快去登录吧", function () {
                                window.location = "/shop/login";
                            });
                        } else {
                            Ap.msg.error(res.msg);
                        }
                    });
                }
            }
        });
    });
</script>
{% endblock %}
